1 /* 2 * hunt-proton: AMQP Protocol library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.proton.codec.DroppingWritableBuffer; 13 14 import hunt.io.ByteBuffer; 15 import hunt.proton.codec.WritableBuffer; 16 import hunt.Integer; 17 import hunt.String; 18 import hunt.proton.codec.ReadableBuffer; 19 20 class DroppingWritableBuffer : WritableBuffer 21 { 22 private int _pos = 0; 23 24 override 25 public bool hasRemaining() 26 { 27 return true; 28 } 29 30 override 31 public void put(byte b) 32 { 33 _pos += 1; 34 } 35 36 override 37 public void putFloat(float f) 38 { 39 _pos += 4; 40 } 41 42 override 43 public void putDouble(double d) 44 { 45 _pos += 8; 46 } 47 48 override 49 public void put(byte[] src, int offset, int length) 50 { 51 _pos += length; 52 } 53 54 override 55 public void putShort(short s) 56 { 57 _pos += 2; 58 } 59 60 override 61 public void putInt(int i) 62 { 63 _pos += 4; 64 } 65 66 override 67 public void putLong(long l) 68 { 69 _pos += 8; 70 } 71 72 override 73 public int remaining() 74 { 75 return Integer.MAX_VALUE - _pos; 76 } 77 78 override 79 public int position() 80 { 81 return _pos; 82 } 83 84 override 85 public void position(int position) 86 { 87 _pos = position; 88 } 89 90 override 91 public void put(ByteBuffer payload) 92 { 93 _pos += payload.remaining(); 94 payload.position(payload.limit()); 95 } 96 97 override 98 public int limit() 99 { 100 return Integer.MAX_VALUE; 101 } 102 103 override 104 public void put(ReadableBuffer payload) 105 { 106 _pos += payload.remaining(); 107 payload.position(payload.limit()); 108 } 109 110 public void put(String value) 111 { 112 _pos += value.getBytes().length; 113 } 114 }