# Retrieving packet size

**URL:** <https://community.hivemq.com/t/retrieving-packet-size/393>\
**Category:** HiveMQ Extension SDK\
**Created:** [December 11, 2020, 10:50pm UTC](https://community.hivemq.com/t/retrieving-packet-size/393 "2020-12-11T22:50:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpringD](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@SpringD](https://community.hivemq.com/u/SpringD)\
**Post date:** [December 11, 2020, 10:50pm UTC](https://community.hivemq.com/t/retrieving-packet-size/393/1 "2020-12-11T22:50:50Z")

</div>

Hi,

I’m writing a `Publish Inbound Interceptor` that will retrieve the size of a packet sent by a client. I was looking at the methods of `PublishPacket` but couldn’t find one that returns the packet size. Please can anyone let me know if I missed anything?

Thanks!

---

<div class="post-metadata">

**Author:** ![FloLi](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/floli/32/17_2.png) [@FloLi](https://community.hivemq.com/u/FloLi)\
**Post date:** [December 14, 2020, 2:43pm UTC](https://community.hivemq.com/t/retrieving-packet-size/393/2 "2020-12-14T14:43:33Z")

</div>

Hello SpringD,

the encoded size of the message sent by the client is not exposed to the PublishPacket object.

If you are only interested in the payload you can check the length of the payloads bytes like this

```
if(publishPacket.getPayload().isPresent()) {
     System.out.println("Payload size: " + publishPacket.getPayload().get().rewind().remaining());
}
```

---

<div class="post-metadata">

**Author:** ![SpringD](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@SpringD](https://community.hivemq.com/u/SpringD)\
**Post date:** [December 15, 2020, 5:52pm UTC](https://community.hivemq.com/t/retrieving-packet-size/393/3 "2020-12-15T17:52:13Z")

</div>

> [@FloLi](#):
>
> check the length of the payloads bytes

Hi FloLi,

Thanks! That’s very helpful.
