com.h3c.of.lib.msg

## Class BucketFactory

- java.lang.Object
- - com.h3c.of.lib.AbstractFactory
  - - com.h3c.of.lib.msg.BucketFactory

-     public class BucketFactory
      extends AbstractFactory

  Provides facilities for parsing, creating and encoding `Bucket` instances.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MutableBucket` | `createMutableBucket(ProtocolVersion pv)` Creates a mutable bucket instance.
    `static void` | `encodeBucket(Bucket bucket, OfPacketWriter pkt)` Encodes a bucket, writing it into the supplied buffer.
    `static void` | `encodeBucketList(List<Bucket> buckets, OfPacketWriter pkt)` Encodes a list of buckets, writing them into the supplied buffer.
    `static int` | `getLength(Bucket bkt)` Returns the length for the given bucket, in bytes.
    `static List<Bucket>` | `parseBucketList(int targetRi, OfPacketReader pkt, ProtocolVersion pv)` Parses a list of bucket structures from the supplied buffer.
    `protected String` | `tag()` Returns an identifying tag for the bucket factory.
    `static String` | `toDebugString(int indent, List<Bucket> bkt)` Outputs a list of buckets in debug string format.

    - ### Methods inherited from class com.h3c.of.lib.AbstractFactory

      `mpe, mpe, mpe, mpe`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### tag

          protected String tag()

      Returns an identifying tag for the bucket factory.
      Specified by:
        `tag` in class `AbstractFactory`
      Returns:
        an identifying tag

    - #### parseBucketList

          public static List<Bucket> parseBucketList(int targetRi,
                                     OfPacketReader pkt,
                                     ProtocolVersion pv)
                                              throws MessageParseException

      Parses a list of bucket structures from the supplied buffer. The caller must calculate and specify the target reader index of the buffer that marks the end of the list, so we know when to stop.

      Note that this method causes the reader index of the underlying `PacketBuffer` to be advanced by the length of the list, which should leave the reader index at `targetRi`.

      This method delegates to `parseBucket(com.h3c.of.lib.OfPacketReader, com.h3c.of.lib.ProtocolVersion)` for each individual bucket.

      Parameters:
        `targetRi` - the target reader index
        `pkt` - the data buffer
        `pv` - the protocol version
      Returns:
        a list of parsed buckets
      Throws:
        `MessageParseException` - if unable to parse the structure

    - #### createMutableBucket

          public static MutableBucket createMutableBucket(ProtocolVersion pv)

      Creates a mutable bucket instance.
      Parameters:
        `pv` - the protocol version
      Returns:
        a mutable bucket
      Throws:
        `VersionNotSupportedException` - if the version is not supported
        `VersionMismatchException` - if the version is < 1.1

    - #### encodeBucket

          public static void encodeBucket(Bucket bucket,
                          OfPacketWriter pkt)

      Encodes a bucket, writing it into the supplied buffer. Note that this method causes the writer index of the underlying `PacketBuffer` to be advanced by the length of the bucket.
      Parameters:
        `bucket` - the bucket
        `pkt` - the buffer into which the bucket is to be written

    - #### encodeBucketList

          public static void encodeBucketList(List<Bucket> buckets,
                              OfPacketWriter pkt)

      Encodes a list of buckets, writing them into the supplied buffer. Note that this method causes the writer index of the underlying `PacketBuffer` to be advanced by the length of the written buckets.
      Parameters:
        `buckets` - the list of buckets
        `pkt` - the buffer into which the buckets are to be written

    - #### getLength

          public static int getLength(Bucket bkt)

      Returns the length for the given bucket, in bytes.
      Parameters:
        `bkt` - the target bucket
      Returns:
        the length of the bkt
      Throws:
        `NullPointerException` - if the bkt is null

    - #### toDebugString

          public static String toDebugString(int indent,
                             List<Bucket> bkt)

      Outputs a list of buckets in debug string format.
      Parameters:
        `indent` - the additional indent (number of spaces)
        `bkt` - the list of buckets
      Returns:
        a multi-line string representation of the list of buckets

Copyright © 2014. All Rights Reserved.