trait Codec[A] extends AnyRef
Codecs allow a writer to deal with the case where we have a buffer overflow
when attempting to write all data to the buffer. This lets the writer return
some state indicating more data needs to be written. This state is then
given to a writeMore method so it can finish the writing. It may take
several calls to writeMore before it all is finally written.
- Self Type
- Codec[A]
- Alphabetic
- By Inheritance
- Codec
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- abstract type S
Abstract Value Members
-
abstract
def
encodedSize(a: A): Int
Returns the exact encoded size of
a. -
abstract
def
read(buffer: ByteBuffer): A
Reads a value of type
Afrombuffer.Reads a value of type
Afrombuffer. This should generally follow the contract thatwriteUnsafe(a, buffer); read(buffer) == a. -
abstract
def
writeInit(a: A, buffer: ByteBuffer): Option[S]
Initiate a write.
Initiate a write. If a is successfully written (in its entirety) to
buffer, thenNoneis returned. Otherwise,Some(s)is returned, indicating that some more data (ie.s) still needs to be written usingwriteMore(s, _). This last condition will normally happen when we run out of space in the buffer, soawas only partially written. -
abstract
def
writeMore(s: S, buffer: ByteBuffer): Option[S]
Writes the remaining data from a call to
writeInittobuffer.Writes the remaining data from a call to
writeInittobuffer. If this is written completely and successfully,Noneis returned. Otherwise,Some(s2)is returned, which contains more data to be written withwriteMore. -
abstract
def
writeUnsafe(a: A, buffer: ByteBuffer): Unit
Performs an *unsafe* write of
atobuffer.Performs an *unsafe* write of
atobuffer. This does not perform any safety checks and assumesbufferhas at leastencodedSize(a)bytes remaining. The behaviour if this is not the case is undefined.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def as[B](to: (B) ⇒ A, from: (A) ⇒ B): Codec[B]
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
maxSize(a: A): Int
Returns an upper bound on the size of
a. -
def
minSize(a: A): Int
Returns a lower bound on the space required in a buffer so that
acan be written. -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
skip(buffer: ByteBuffer): Unit
This is similar to
read(buffer), except that a value does not actually need to be returned. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
write[M[_]](a: A)(implicit M: ByteBufferMonad[M]): M[Unit]
Writes
ausing aByteBufferMonad.Writes
ausing aByteBufferMonad. This is much slower than just using writeInit/writeMore. -
def
writeAll(a: A)(acquire: () ⇒ ByteBuffer, used: List[ByteBuffer] = Nil): List[ByteBuffer]
Writes
aentirely to a series ofByteBuffers returned byacquire.Writes
aentirely to a series ofByteBuffers returned byacquire. The returned set ofByteBuffers is in reverse order, so that calls towriteAllcan be chained by passing in the previous result toused.